home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11532 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.iadfw.net!usenet
  2. From: Larry Weiss <lfw@iadfw.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Determining the length of an int in string form
  5. Date: Sun, 24 Mar 1996 17:53:11 -0600
  6. Organization: customer of Internet America
  7. Message-ID: <3155E067.3261@iadfw.net>
  8. References: <3146D058.DD7@cbm.com> <4i7uth$qph@inet-nntp-gw-1.us.oracle.com> <DoE38u.GIH@iquest.net> <4in1ga$ogk@airdmhor.gen.nz> <Pine.SOL.3.91.960319172332.4535A-100000@darwin.UCSC.EDU> <314F65D3.6A8@oc.com> <827703345snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: dal25-03.ppp.iadfw.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (Win16; I)
  14.  
  15. Lawrence Kirby wrote:
  16.  > 
  17.  > In article <314F65D3.6A8@oc.com> lfw@oc.com "Larry Weiss" writes:
  18.  > >I've seen some suggestions to try to fprintf() once to a file (maybe a
  19.  > >"bit-bucket") to get a handle on how many characters sprintf() may use,
  20.  > >but I don't think that that's guaranteed by the C Standard to absolutely
  21.  > >correspond.
  22.  > 
  23.  > I think it must. 7.9.6.5:
  24.  > 
  25.  > "The sprintf function is equivalent to fprintf, except that the argument s
  26.  >  specifies an array into which the generated output is to be written,
  27.  >  rather than to a stream."
  28.  > 
  29.  > So the same number of characters are being written/output in both cases,
  30.  > unless a write error occurred in fprintf which you can detect.
  31.  > 
  32.  
  33.  
  34. We all discussed this, maybe a year ago, and what I was remembering was
  35. the issue with the representation of end-of-line on the file system, and
  36. whether this affected the return value of fprintf().   Seems safe enough
  37. that if you never indicate the end-of-line condition (usually via the
  38. \n in in format string) then that is not an issue (even on a mainframe,
  39. with those block-mode fixed-length records).    
  40.  
  41. Now what I'd really like to see in the next revision of the standard library
  42. would be an snprintf() with the extra argument to declare only so many writeable
  43. chars in the buffer, and a return code to indicate logical attempts to write
  44. beyond that limit.
  45.